package com.yhsimon.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public String login(String username, String pwd, HttpSession session, Model model){
        if (username==null||username==""){
            return "login";
        }
        session.setAttribute("userInfo", username);
        model.addAttribute("username", username);
        return "main";
    }

    @RequestMapping("/main")
    public String main(){
        return "main";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
//        session.invalidate();
        session.removeAttribute("userInfo");
        return "redirect:/user/login";
    }
}
